<?php
/**
 * spsNewsletter controller for newsletter management
 * 
 * @author Satyan Shah <joomlaDesign@modernbridge.com>
 * @link http://www.modernbridge.com
 * @license GNU/GPL
 */


// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die();


// extend our main controller for the newsletter
class spsNewslettersControllernewsletter extends spsNewslettersController
{
	function __construct()
	{
		parent::__construct();

		// Register Extra tasks, in this case we are saying to treat add like edit;
		$this->registerTask( 'add'  , 'edit' );

	}

	function edit()
	{  
		// the view is now (propertly) handled by the controller. The call below shoulnd't be needed
		JRequest::setVar( 'layout', 'form'  );
		JRequest::setVar('hidemainmenu', 1);
		parent::display();
	}

	function save()
	{
		// get the newsletter to save. 
		// Note: We MUST use JREQUEST_ALLOW raw here, the JREQUEST_HTML filter seems to stringent
		$text = JRequest::getVar( 'newsletter','', 'post', 'string',JREQUEST_ALLOWRAW);;
		// get our model
		$model = $this->getModel('newsletter');
		// attempt to store, update user accordingly
		if ($model->store($post)) {
			$msg = JText::_( 'spsNewsletter: Newsletter saved' );
		} 
		else {
			$msg = JText::_( 'spsNewsletter: Error saving Newsletter' );
		}

		// redirect (to same controller, since task won't be add, edit, or new we will return to the list of newsletters)
		$link = 'index.php?option=com_spsNewsletter&controller=newsletter';
		$this->setRedirect($link, $msg);
    
    
	}

	function remove()
	{
		// get the model
		$model = $this->getModel('newsletter');
    
		// attempt to delete, update user accordingly
		if(!$model->delete()) {
			$msg = JText::_( 'spsNewsletter: One or more newsletters could not be deleted' );
		} 
		else {
			$msg = JText::_( 'spsNewsletter: Newsletter deleted' );
		}
		// redirect
		$this->setRedirect( 'index.php?option=com_spsNewsletter&controller=newsletter', $msg );
	}

	
	function cancel()
	{	
		// updated msg field for user, redirect back to newsletter controller
		$msg = JText::_( 'Operation Cancelled' );
		$this->setRedirect( 'index.php?option=com_spsNewsletter&controller=newsletter', $msg );
	}

}
?>
